﻿using System.Collections.Generic;
using System.IO;
using System.Linq;
using phudieuhungthinh.BL.Model;
using phudieuhungthinh.DAL;
using phudieuhungthinh.DAL.Repositories;

namespace phudieuhungthinh.BL
{
    public class ProductCategoriesImpl
    {
        public List<ProductCategoriesModel> GetProductCategories(int productId)
        {
            var producCategoriesRepository = new ProductCategoriesRepository();
            List<ProductCategoriesModel> productCategories = (from x in producCategoriesRepository.GetAllProductCategories()
                                                              where x.ProductID == productId
                                                              select new ProductCategoriesModel(x)).ToList();
            return productCategories;
        }        

        public void AddProductCategories(ProductCategoriesModel productCategoriesModel)
        { 
            var producCategoriesRepository = new ProductCategoriesRepository();
            producCategoriesRepository.AddProductCategories(productCategoriesModel.MapProductCategories());
            productCategoriesModel.Commit();
        }

        public List<ProductCategoriesModel> GetProductCategoriesByCategory(int categoryId)
        {
            var producCategoriesRepository = new ProductCategoriesRepository();
            List<ProductCategoriesModel> productCategories = (from x in producCategoriesRepository.GetAllProductCategories()
                                                              where x.CategoryID == categoryId
                                                              select new ProductCategoriesModel(x)).ToList();
            return productCategories;
        }
    }
}
